<?php
/**

 * @version $Id: all.php,v 1.4 2009/06/04 20:13:37 dgravato Exp $

 * @package    sketchup

 * @subpackage 

 * @author     Chris Borkowski {@link http://www.guggenheim.org}

 * @author     Created on 04-April-2009

 */
 
// no direct access

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.model' );

class ModelSketchupsAll extends JModel
{
		/**
   		* All Items 
   		* @ returns array
   		*/
	
		var $_sketchups = null;

		/**
		* Sketchup ata array
	 	* @var array
	 	*/
		var $_data = null;
		
		/**
   		* Items total
   		* @var integer
   		*/

		var $_total = null;
 
  		/**
  	 	* Pagination object
   		* @var object
   		*/
  		var $_pagination = null;
	
	 	/* Constructor
	 	*  !com_sketchup.limit or global.list.limit
	 	*  
	 	*/
	 	
	 	function __construct()
  		{
        parent::__construct();
 
        global $mainframe, $option;
 
        // Get pagination request variables
        $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
        $limitstart = $mainframe->getUserStateFromRequest($option.'.limitstart', 'limitstart', 0, 'int');

        $this->setState('limit', $limit);
        $this->setState('limitstart', $limitstart);
                
  		}

	 	/**
 		* Get itemized data
 		*
 		* @access public
 		* @return array
 		*/
 		function getData()
		{
    	if (empty($this->_data))
    	{
        $query = $this->_buildQuery();
        $limitstart = $this->getState('limitstart');
        $limit = $this->getState('limit');
        $this->_data = $this->_getList($query, $limitstart, $limit);
   		 } 
    
    	return $this->_data;
		}
	 
	 	
		/**
		* Get number of items
 		*
 		* @access public
 		* @return integer
 		*/
		function getTotal()
		{
     	if (empty($this->_total))
    	{
        $query = $this->_buildQuery();
        $this->_total = $this->_getListCount($query);
    	}
 
    	return $this->_total;
		}

		/* Pagination
  		@ 
  		@ access public
  		*/
		
		
		/**
 		* Get a pagination object
 		*
 		* @access public
 		* @return JPagination
 		*/
		function getPagination()
		{
    	if (empty($this->_pagination))
    	{
        // import the pagination library
        jimport('joomla.html.pagination'); 
        // prepare the pagination values
        $total = $this->getTotal();
        $limitstart = $this->getState('limitstart');
        $limit = $this->getState('limit');

        // create the pagination object
        $this->_pagination = new JPagination($total, $limitstart, $limit);
    	}

    	return $this->_pagination;
		}

  		/*
  		Simple Query string, this may get more complex to accept where & order by clauses in the future.
  		
  		@returns string 
  		@access private
  		*/
  		
  		function _buildQuery()
  		{
  		
  		return 'SELECT * FROM #__sketchup WHERE published = "1" ORDER BY p_title ASC';
 
  		}
  			
  		function getList()
		{
	
		//check to see if the data is already loaded if not load it
		if(empty($this->_sketchups))
		{
			
			$query = $this->_buildQuery();
			$limitstart =$this->getstate('limitstart');
			$limit= $this->getState('limit');
			$this->_sketchups = $this->_getList($query, $limitstart, $limit );
			
		}
			
		
		return $this->_sketchups;
		
		} // we're all good



} //the end


?>